<!--  活动列表组件  -->
<template>
  <div>
    <div class="">
      <h2>老乡会用户列表</h2>
      <el-table
        :loading="listLoading"
        :data="list.slice((this.currentPage-1)*pagesize,currentPage*pagesize)"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <el-table-column
          align="center"
          prop="userId"
          label="用户Id"
          width="170px"
        />

        <el-table-column
          align="center"
          prop="userInfo.userName"
          label="用户姓名"
          width="100px"
        />

        <el-table-column
          align="center"
          prop="userInfo.userPartName"
          label="用户学部"
          width="150px"
        />

        <el-table-column
          align="center"
          prop="userInfo.userClassName"
          label="用户班级"
          width="150px"
        />

        <el-table-column
          align="center"
          prop="userInfo.userOrigin"
          label="用户生源地"
          width="200px"
        />

        <el-table-column
          align="center"
          prop="userInfo.userPhone"
          label="用户生源地"
          width="200px"
        />
        <el-table-column
          align="center"
          prop="userInfo.userEmail"
          label="用户生源地"
          width="200px"
        />

        <el-table-column
          align="center"
          prop="userOldStatus"
          label="是否加入老乡会"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.userOldStatus=='1'">加入</span>
            <span v-if="scope.row.userOldStatus=='2'" style="color: blue;"><b>未加入</b></span>
          </template>
        </el-table-column>

        <!-- <el-table-column
          align="center"
          prop="actMemberWay"
          label="录取方式"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.actMemberWay=='1'">手动审核</span>
            <span v-if="scope.row.actMemberWay=='2'">无需审核</span>
          </template>
        </el-table-column> -->

        <el-table-column
          align="center"
          prop="userStatus"
          label="用户状态"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.userStatus=='0'">封禁状态</span>
            <span v-if="scope.row.userStatus=='1'">未封禁状态</span>

          </template>
        </el-table-column>

        <el-table-column align="center" label="查看详情">
          <template slot-scope="Scope">

            <el-button type="primary" icon="el-icon-search" size="mini" @click="getUserInfoInfo(Scope.row.userId)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <user-info ref="info" :user-id="userId" :show="show" />
  </div>

</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';

import Info from '../../components/user/info.vue'
import { getUserInfoById, auditActivityByActId1 } from '../../api/userInfo.js'
export default {
  name: '',
  // import引入的组件需要注入到对象中才能使用
  components: {
    'user-info': Info
  },
  props: {
    type: String
  },
  data() {
    // 这里存放数据
    return {
      userId: '',
      show: false,
      dialogFormVisible: false,
      search: {},
      listLoading: false,
      list: [],
      currentPage: 1, // 默认显示页面为1
      pagesize: 10 //    每页的数据条数
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getUserInfo()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    // 每页下拉显示数据
    handleSizeChange(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange(currentPage) {
      console.log(this)
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },

    getUserInfo() {
      getUserInfoById().then((data) => {
        console.log('data数据', data)
        this.list = data.obj
        this.listLoading = false
      })
    },

    getUserInfoInfo(userId) {
      this.$refs.info.showInfo(userId)
    },

    auditstatus(userId, userOldStatus, userStatus, userPwd, userType) {
      getUserInfoById(userId).then((data) => {
        this.user = data.obj
        console.log('data数据为：', this.user)
        console.log('userId为：', userId)
        if (userOldStatus === '2') {
          auditActivityByActId1(userId, userOldStatus, userStatus, userPwd, userType).then((data) => {
            this.message = data.msg
            this.$message({
              showClose: true,
              message: '修改成功',
              type: 'success'

            })
            console.log(this.message)
            location.reload()
          })
        } else {
          this.$message({
            showClose: true,
            message: '该用户已经加入老乡会',
            type: 'error'
          })
        }
      })
    }

  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style scoped>

</style>
